var HOME = {
	boxTabLeft: -66,
	is_sending: false,
	init : function() {
		 var menuActive = $('#page-menu a.a-menu-home, #menu-top-page a.a-menu-home');
		 menuActive.addClass('a-menu-home-active');
		$('#nivo-slider').nivoSlider({
			effect : "random",
			slices : 15,
			boxCols : 8,
			boxRows : 4,
			animSpeed : 500,
			pauseTime : 4500,
			startSlide : 0,
			directionNav : false,
			controlNav : true,
			controlNavThumbs : false,
			pauseOnHover : false,
			randomStart: true,
			manualAdvance : false
		});
		
		$('#loan-view-more').click(function(){
			HOME.initScrollLoan();
			$(this).remove();
		});
		$('#period-view-more').click(function(){
			HOME.initScrollPeriod();
			$(this).remove();
		});
		$('#card-view-more').click(function(){
			HOME.initScrollCard();
			$(this).remove();
		});
		
		$("ul.tabs").tabs("div.panes > div");
		
		HOME.loadLoans(1);
		HOME.loadCards(1);
		HOME.loadPeriods(1);
		HOME.loadFaqs(1);
		HOME.clickChange();
		
		
	},
	initScrollPeriod: function(){
		$('div.period-scrollbar').each(function(){
			var obj = $(this);
			$('div.for-period-scroll',obj).mCustomScrollbar({
				scrollButtons:{
					enable:false
				},
				scrollInertia:150,
				advanced:{
					updateOnBrowserResize:true, 
					updateOnContentResize:true, 
					autoExpandHorizontalScroll:false 
				},
				callbacks:{
					onTotalScroll:function(){
						HOME.loadNextPeriods(obj.attr('data-currency'));
					},
					onTotalScrollOffset:5
				}
			});
		});
	},
	initScrollLoan: function(){
		$('div.loan-scrollbar').each(function(){
			var obj = $(this);
			$('div.for-loan-scroll',obj).mCustomScrollbar({
				scrollButtons:{
					enable:false
				},
				scrollInertia:150,
				advanced:{
					updateOnBrowserResize:true, 
					updateOnContentResize:true, 
					autoExpandHorizontalScroll:false 
				},
				callbacks:{
					onTotalScroll:function(){
						HOME.loadNextLoans(obj.attr('data-loan'));
					},
					onTotalScrollOffset:5
				}
			});
		});
	},
	initScrollCard: function(){
		$('div.card-scrollbar').each(function(){
			var obj = $(this);
			$('div.for-card-scroll',obj).mCustomScrollbar({
				scrollButtons:{
					enable:false
				},
				scrollInertia:150,
				advanced:{
					updateOnBrowserResize:true, 
					updateOnContentResize:true, 
					autoExpandHorizontalScroll:false 
				},
				callbacks:{
					onTotalScroll:function(){
						HOME.loadNextCards(obj.attr('data-card'));
					},
					onTotalScrollOffset:5
				}
			});
		});
	},
	clickChange: function(){
		$('div.click-change').click(function(){
			var obj = $(this);
			$('div.click-change').each(function(){
				if($(this).attr('data-refer')!=obj.attr('data-refer')){
					$(this).attr('class','title-arrow click-change title-arrow-none');
					obj.attr('class','title-arrow click-change ');
					$('div#'+$(this).attr('data-refer')).fadeOut('fast','linear',function(){
						$('div#'+obj.attr('data-refer')).fadeIn('fast','linear');
					});
					$('div#'+$(this).attr('data-refer')+'-top').fadeOut('fast','linear',function(){
						$('div#'+obj.attr('data-refer')+'-top').fadeIn('fast','linear');
					});
				}
			});
			HOME.clickChange();
		});
	},
	
	loadPeriods: function(page){
		$('div.banking-period-rate').each(function(){
			var obj = $(this);
			$.ajax({
				type: "POST",
				url: '/home/getPeriods',
				data: {
					'page': page,
					'currency_id': obj.attr('data-currency')
				},
				cache: false,
				success: function(data){
					obj.html(data);
					if(parseInt(page,10)==1){
						HOME.loadNextPeriods(obj.attr('data-currency'));
					}
				}
			});
		});
	},
	loadLoans: function(page){
		$('div.banking-loan-rate').each(function(){
			var obj = $(this);
			$.ajax({
				type: "POST",
				url: '/home/getLoans',
				data: {
					'page': page,
					'banking_loan_id': obj.attr('data-loan')
				},
				cache: false,
				success: function(data){
					obj.html(data);
					if(parseInt(page,10)==1){
						HOME.loadNextLoans(obj.attr('data-loan'));
					}
				}
			});
		});
	},
	loadCards: function(page){ 
		$('div.banking-card-rate').each(function(){
			var obj = $(this);
			$.ajax({
				type: "POST",
				url: '/home/getCards',
				data: {
					'page': page,
					'banking_card_id': obj.attr('data-card')
				},
				cache: false,
				success: function(data){
					obj.html(data);
					if(parseInt(page,10)==1){
						HOME.loadNextCards(obj.attr('data-card'));
					}
				}
			});
		});
	},
	loadFaqs: function(page){
		$('div.faq-inner').each(function(){
			var obj = $(this);
			$.ajax({
				type: "POST",
				url: '/home/getFaq',
				data: {
					'page': page,
					'cate_id': obj.attr('data-faq')
				},
				cache: false,
				success: function(data){
					obj.html(data);
					if(parseInt(page,10)==1){
						HOME.loadNextFaqs(obj.attr('data-faq'));
					}
				}
			});
		});
	},
	loadNextPeriods:function(currency_id){
		if(parseInt($('#period_next_page_cid'+currency_id).attr('data-value'),10) <= 0){
			return;
		}
		$.ajax({
			type: "POST",
			url: '/home/getPeriods',
			data: {
				'page': $('#period_next_page_cid'+currency_id).attr('data-value'),
				'currency_id': currency_id
			},
			cache: false,
			success: function(data){
				$('#tbl-period_cid'+currency_id).append(data);
			}
		});
	},
	loadNextLoans:function(banking_loan_id){
		if(parseInt($('#loan_next_page_cid'+banking_loan_id).attr('data-value'),10) <= 0){
			return;
		}
		$.ajax({
			type: "POST",
			url: '/home/getLoans',
			data: {
				'page': $('#loan_next_page_cid'+banking_loan_id).attr('data-value'),
				'banking_loan_id': banking_loan_id
			},
			cache: false,
			success: function(data){
				$('#tbl-loan_cid'+banking_loan_id).append(data);
			}
		});
	},
	loadNextCards:function(banking_card_id){
		if(parseInt($('#card_next_page_cid'+banking_card_id).attr('data-value'),10) <= 0){
			return;
		}
		$.ajax({
			type: "POST",
			url: '/home/getCards',
			data: {
				'page': $('#card_next_page_cid'+banking_card_id).attr('data-value'),
				'banking_card_id': banking_card_id
			},
			cache: false,
			success: function(data){
				$('#tbl-card_cid'+banking_card_id).append(data);
			}
		});
	},
	loadNextFaqs:function(cate_id){
		if(parseInt($('#faq_next_page_cid'+cate_id).attr('data-value'),10) <= 0){
			return;
		}
		$.ajax({
			type: "POST",
			url: '/home/getFaq',
			data: {
				'page': $('#faq_next_page_cid'+cate_id).attr('data-value'),
				'cate_id': cate_id
			},
			cache: false,
			success: function(data){
				$('#tbl-faq_cid'+cate_id).append(data);
			}
		});
	},	
	loadConsultings: function(){
		$('div.support.load').each(function(){
			var obj = $(this);
			$.ajax({
				type: "POST",
				url: '/home/getConsultingOnline',
				data: {
					'page': 1,
					'banking_type': obj.attr('data-banking-type')
				},
				cache: false,
				success: function(data){
					obj.html(data);
				}
			});
		});
	}
}